package com.ruoyi.system.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.TBProductType;
import com.ruoyi.system.domain.TBDevice;
import com.ruoyi.system.service.ITBDeviceService;
import com.ruoyi.system.service.ITBProductTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TBFiles;
import com.ruoyi.system.service.ITBFilesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 附件Controller
 * 
 * @author pspyy
 * @date 2022-03-04
 */
@RestController
@RequestMapping("/system/files")
@Api("附件管理")
public class TBFilesController extends BaseController
{
    @Autowired
    private ITBFilesService tBFilesService;

    /**
     * 查询附件列表
     */
    @PreAuthorize("@ss.hasPermi('system:files:list')")
    @GetMapping("/list")
    @ApiOperation("查询附件列表")
    public TableDataInfo list(TBFiles tBFiles)
    {
        startPage();
        List<TBFiles> list = tBFilesService.selectTBFilesList(tBFiles);
        return getDataTable(list);
    }

    /**
     * 根据ids查查询数据
     */
    @GetMapping("/fileList/{fileIds}")
    @ApiOperation("根据ids查查询数据")
    public List<TBFiles> list(@PathVariable String[] fileIds)
    {
        List<TBFiles> list = tBFilesService.selectFileListByIds(fileIds);
        return list;
    }

    /**
     * 导出附件列表
     */
    @PreAuthorize("@ss.hasPermi('system:files:export')")
    @Log(title = "附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出附件列表")
    public void export(HttpServletResponse response, TBFiles tBFiles)
    {
        List<TBFiles> list = tBFilesService.selectTBFilesList(tBFiles);
        ExcelUtil<TBFiles> util = new ExcelUtil<TBFiles>(TBFiles.class);
        util.exportExcel(response, list, "附件数据");
    }

    /**
     * 获取附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:files:query')")
    @GetMapping(value = "/{fileId}")
    @ApiOperation("获取附件详细信息")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId)
    {
        return AjaxResult.success(tBFilesService.selectTBFilesByFileId(fileId));
    }

    /**
     * 新增附件
     */
    @PreAuthorize("@ss.hasPermi('system:files:add')")
    @Log(title = "附件", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增附件")
    public AjaxResult add(@RequestBody TBFiles tBFiles)
    {
        return toAjax(tBFilesService.insertTBFiles(tBFiles));
    }

    /**
     * 修改附件
     */
    @PreAuthorize("@ss.hasPermi('system:files:edit')")
    @Log(title = "附件", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改附件")
    public AjaxResult edit(@RequestBody TBFiles tBFiles)
    {
        return toAjax(tBFilesService.updateTBFiles(tBFiles));
    }

    /**
     * 删除附件
     */
    @PreAuthorize("@ss.hasPermi('system:files:remove')")
    @Log(title = "附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds)
    {
        return toAjax(tBFilesService.deleteTBFilesByFileIds(fileIds));
    }
}
